package com.jcl.recruit.corp.mapper;

import com.jcl.recruit.corp.model.Subcompany;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author 刘明新
 * @date 2018/8/2 下午1:37
 */
public interface SubcompanyMapper {

    @Select({
            "<script>",
            "select * from subcompany",
            "<if test=\"superId != null\">where super_id = #{superId}</if>",
            "order by id desc",
            "</script>"
    })
    List<Subcompany> selectAllComanyInfosBySuperId(@Param("superId") Integer superId);

    @Select({
            "select * from subcompany where code = #{code}"
    })
    Subcompany findOneByCode(@Param("code") String code);

    @Select({
            "<script>",
            "select * from subcompany",
            "<where>",
            "<if test=\"email != null and email != ''\"> email like '%${email}' </if>",
            "<if test=\"name != null and name != ''\"> or fullname = #{name} </if>",
            "</where>",
            "order by id desc",
            "</script>"
    })
    List<Subcompany> findOneByEmail(@Param("email") String email, @Param("name") String name);

    @Select({
            "select * from subcompany where id = #{id}"
    })
    Subcompany findOneById(@Param("id") Integer id);


    @InsertProvider(type= SubcompanyProvider.class, method = "insertSelective")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int add(Subcompany company);

    @UpdateProvider(type=SubcompanyProvider.class, method = "updateSelective")
    int update(Subcompany company);

    @Update({
            "update subcompany set add_user = #{userId} where id = #{id} "
    })
    int updateAddUser(@Param("corpCode") String corpCode,
                      @Param("id") Integer id,
                      @Param("userId") Integer userId);


}
